package com.itheima.controller;

import com.itheima.R;
import com.itheima.dto.PmsProductCategoryParam;
import com.itheima.service.PmsProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chensen
 * @create 2022/10/13/20:29
 */
@RestController
@RequestMapping("productCategory")
public class PmsProductCategoryController {
    @Autowired
    private PmsProductCategoryService pmsProductCategoryService;

    /**
     * 添加商品分类
     * @param productCategoryParam
     * @return
     */
    @PostMapping("create")
    public R create(@RequestBody PmsProductCategoryParam productCategoryParam){
        return pmsProductCategoryService.create(productCategoryParam);
    }

    /**
     * 删除商品分类
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public R delete(@PathVariable Long id){
        return pmsProductCategoryService.delete(id);
    }

    /**
     * 查询所有一级分类及子分类
     * @return
     */
    @GetMapping("list/withChildren")
    public R listWithChildren(){
        return pmsProductCategoryService.listWithChildren();
    }

    /**
     * 分页查询商品分类
     * @param parentId
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("list/{parentId}")
    public R getList(@PathVariable Long parentId,
                                @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        return pmsProductCategoryService.getList(parentId,pageNum,pageSize);
    }

    /**
     * 修改导航栏显示状态
     * @param ids
     * @param navStatus
     * @return
     */
    @PostMapping("update/navStatus")
    public R updateNavStatus(@RequestParam("ids") List<Long> ids, @RequestParam("navStatus") Integer navStatus){
        return pmsProductCategoryService.updateNavStatus(ids,navStatus);
    }

    /**
     * 修改显示状态
     * @param ids
     * @param showStatus
     * @return
     */
    @PostMapping("update/showStatus")
    public R updateShowStatus(@RequestParam("ids") List<Long> ids, @RequestParam("showStatus") Integer showStatus){
        return pmsProductCategoryService.updateShowStatus(ids,showStatus);
    }

    /**
     * 修改商品分类
     * @param id
     * @param productCategoryParam
     * @return
     */
    @PostMapping("update/{id}")
    public R update(@PathVariable Long id,
                               @RequestBody PmsProductCategoryParam productCategoryParam){
        return pmsProductCategoryService.update(id,productCategoryParam);
    }

    /**
     *根据id获取商品分类
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public R getItem(@PathVariable Long id){
        return pmsProductCategoryService.getItem(id);
    }

}
